package com.xinzhidi.common.model;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
public class TreeNode {

    /**
     * 主键
     */
    protected String id;

    /**
     * 父节点id
     */
    protected String parentNodeId;

    /**
     * 节点id
     */
    protected String nodeId;

    /**
     * 节点名称
     */
    protected String nodeName;

    /**
     * 子节点几何
     */
    protected List<TreeNode> children;

    public void add(TreeNode node) {
        if (CollectionUtils.isEmpty(children)) {
            children = new ArrayList<>();
        }
        children.add(node);
    }
}
